using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Module.CMS.Library;
using NCS.Library.Utilities;
using NCS.Module.CMS.Library.Definitions;
using NCS.Module.CMS.Library.Zones;
using NCS.Library;
using NCS.Library.Components.Portal;

namespace NCS.Module.CMS.Web.HomePage
{
    public partial class ContentFilters : CMSWebControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (curZone.Zone_Authorize > 0)//kieu hien thi dang nhap
            {
                Boolean check = false;
                if (CurrentUser != null)
                {
                    DataTable dt = PortalController.GetPortals(CurrentUser.UserID, AppEnv.GetLanguage());
                    if (dt.Rows.Count > 0)
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            if (dt.Rows[i]["PortalID"].ToString() == AppEnv.PortalId())
                            {
                                check = true;
                            }
                        }
                    }
                    if (check == false)
                    {
                        Response.Redirect("/", true);
                        return;
                    }
                }
                else
                {
                    Session["UrlKey"] = HttpContext.Current.Request.RawUrl;
                    Response.Redirect("/");
                    //this.PlaceHolder1.Controls.Add(LoadControl("Login.ascx"));
                    return;
                }
            }

            DataTable tbl = ZoneController.GetZones(this.curZone.Zone_ID, AppEnv.PortalId());
            if (tbl != null && tbl.Rows.Count >= 0)
            {
                if (tbl.Rows.Count > 0)
                {
                    HeadZone headzone;
                    for (int i = 0; i < tbl.Rows.Count; i++)
                    {
                        headzone = (HeadZone)LoadControl("HeadZone.ascx");
                        headzone.LoadZone(Int32.Parse(tbl.Rows[i]["Zone_ID"].ToString()));
                        this.PlaceHolder1.Controls.Add(headzone);
                    }
                }
                else if (tbl.Rows.Count == 0)
                {
                    this.PlaceHolder1.Controls.Add(LoadControl("ContentListSimple.ascx"));
                }
            }
        }
    }
}